<?php

declare(strict_types=1);

namespace Plugin\Attractions\HaiKang\Common;

use Hyperf\Di\Annotation\Inject;

class HKAPI
{
    #[Inject()]
    private HKClient $client;
    /**
     * 查询设备所有分组
     * @return array|mixed
     */
    public function groupsList()
    {
        return $this->client->request('GET', "/api/v1/open/basic/groups/actions/listAll");
    }

    /**
     * 分组查询设备列表
     * @param $params
     * @return array|mixed
     */
    public function devicesList(array $params)
    {
        return $this->client->request('GET', "/api/v1/open/basic/devices/list?groupNo={$params['group_no']}&pageNo={$params['page']}&pageSize=999");
    }

    /**
     * 查询单个设备信息
     * 
     */
    public function deviceInfo(array $params)
    {
        return $this->client->request('GET', "/api/v1/open/basic/devices/get?deviceSerial={$params['device_serial']}");
    }

    /**
     * 查询设备状态
     */
    public function deviceStatus(array $params)
    {
        return $this->client->request('GET', "/api/v1/ezviz/devices/queryDeviceStatus?deviceSerial={$params['device_serial']}");
    }

    /**
     * 获取设备总数
     */
    public function deviceTotal()
    {
        return $this->client->request('GET', '/api/v1/open/basic/devices/actions/deviceCount');
    }

    /**
     * 查询设备通道列表
     */
    public function deviceChannelList(array $params)
    {
        return $this->client->request('GET', "/api/v1/open/basic/channels/list?deviceSerial={$params['device_serial']}&pageNo={$params['page']}&pageSize=999");
    }

    /**
     * 同步设备通道信息
     */
    public function syncDeviceChannel(array $params)
    {
        return $this->client->request('POST', '/api/v1/open/basic/channels/actions/sync', [
            'json' => [
                'deviceSerial' => $params['device_serial']
            ],
            [
                'Content-Type' => 'application/json'
            ]
        ]);
    }

    /**
     * 获取区域关注度配置
     */
    public function getAreaAttentionConfig($params)
    {
        return $this->client->request('GET', "/api/v1/device/isapi/intelligent/personQueueDetection/config?deviceSerial={$params['device_serial']}");
    }

    /**
     * 配置区域关注度
     */
    public function setAreaAttentionConfig($params)
    {
        return $this->client->request(
            'POST',
            "/api/v1/device/isapi/intelligent/personQueueDetection/config",
            [
                'json' => $params,
            ],
            [
                'Content-Type' => 'application/json'
            ]);
    }

    /**
     * 生成热度图
     */
    public function generateHeatMap(array $params)
    {
        return $this->client->request('POST', '/api/v1/device/isapi/intelligent/personQueueDetection/heatMapPicture/actions/generate', [
            'json' => $params
        ],[
            'Content-Type' => 'application/json'
        ]);
    }

    /**
     * 获取热度图
     */
    public function getHeatMap(array $params)
    {
        return $this->client->request('GET', "/api/v1/device/isapi/intelligent/personQueueDetection/heatMapPicture?deviceSerial={$params['device_serial']}&channelNo={$params['channel_no']}");
    }

    /**
     * 获取热度图配置
     */
    public function getHeatMapConfig(array $params)
    {
        return $this->client->request('GET', "/api/v1/device/isapi/intelligent/personQueueDetection/heatMapConfig?deviceSerial={$params['device_serial']}&channelNo={$params['channel_no']}");
    }

    /**
     * 设置热度图配置
     */
    public function setHeatMapConfig(array $params)
    {
        return $this->client->request('POST', '/api/v1/device/isapi/intelligent/personQueueDetection/heatMapConfig', [
            'json' => $params
        ],
        [
            'Content-Type' => 'application/json'
        ]);
    }

    /**
     * 视频取流认证token
     */
    public function getVideoStreamToken()
    {
        return $this->client->request('POST', '/v1/ezviz/account/info');
    }
}
